﻿package com.gengine.core.frame
{

    public class BaseTimer extends Object implements IBaseTimer
    {
        protected var _running:Boolean = false;
        private var _id:int = 0;
        private var _delay:Number;
        private var _repeatCountCache:Number;
        private var _repeatCount:Number;
        public var currentCount:int;
        private var _interval:int;
        private var _isRepair:Boolean = false;
        private var _enterFrameHandler:Function;
        private var _completeHandler:Function;
        private static var _baseID:int = 0;

        public function BaseTimer(param1:Number, param2:Number)
        {
            this._id = _baseID + 1;
            this.delay = param1;
            this.repeatCount = param2;
            this._repeatCountCache = param2;
            return;
        }// end function

        public function get isRepair() : Boolean
        {
            return this._isRepair;
        }// end function

        public function set isRepair(param1:Boolean) : void
        {
            this._isRepair = param1;
            return;
        }// end function

        public function set repeatCountCache(param1:int) : void
        {
            this._repeatCountCache = param1;
            return;
        }// end function

        public function get repeatCountCache() : int
        {
            return this._repeatCountCache;
        }// end function

        public function get type() : String
        {
            return "";
        }// end function

        public function get id() : int
        {
            return this._id;
        }// end function

        public function addListener(param1:String, param2:Function) : void
        {
            if (param1 == TimerType.COMPLETE)
            {
                this._completeHandler = param2;
            }
            else if (param1 == TimerType.ENTERFRAME)
            {
                this._enterFrameHandler = param2;
            }
            return;
        }// end function

        public function renderer(param1:int, param2:Boolean = false) : void
        {
            if (!param2)
            {
                var _loc_3:String = this;
                var _loc_4:* = this.currentCount + 1;
                _loc_3.currentCount = _loc_4;
                var _loc_3:String = this;
                var _loc_4:* = this.repeatCount - 1;
                _loc_3.repeatCount = _loc_4;
            }
            this._isRepair = param2;
            if (this._enterFrameHandler is Function)
            {
                this._enterFrameHandler(this);
            }
            if (this.repeatCount <= 0)
            {
                this.running = false;
                if (this._completeHandler is Function)
                {
                    this._completeHandler(this);
                }
            }
            return;
        }// end function

        public function get interval() : int
        {
            return this._interval;
        }// end function

        public function set interval(param1:int) : void
        {
            this._interval = param1;
            return;
        }// end function

        public function start() : void
        {
            this.running = true;
            return;
        }// end function

        public function stop() : void
        {
            this.running = false;
            this.currentCount = 0;
            return;
        }// end function

        public function get running() : Boolean
        {
            return this._running;
        }// end function

        public function set running(param1:Boolean) : void
        {
            this._running = param1;
            return;
        }// end function

        public function get delay() : Number
        {
            return this._delay;
        }// end function

        public function set delay(param1:Number) : void
        {
            this._delay = param1;
            return;
        }// end function

        public function get repeatCount() : Number
        {
            return this._repeatCount;
        }// end function

        public function set repeatCount(param1:Number) : void
        {
            this._repeatCount = param1;
            return;
        }// end function

        public function reset() : void
        {
            this.repeatCount = this._repeatCountCache;
            this.currentCount = 0;
            return;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            this._completeHandler = null;
            this._enterFrameHandler = null;
            this.running = false;
            this._repeatCount = 0;
            this.currentCount = 0;
            this._isRepair = false;
            return;
        }// end function

    }
}
